const Directive = {};
Directive.install = function (Vue) {
	Vue.directive('focus', {
		inserted : function (el, { value }) {
			if (value) {
				el.focus();
			}
		},
		componentUpdated : function (el, { value }) {
			if (value) {
				el.focus();
			}
		}
	});
	Vue.directive('click-lock', {
		inserted : function (el, bind) {
			el.addEventListener('click', () => {
				el.disabled = true;
				el.style.pointerEvents = 'none';
				bind
					.value()
					.then(
						() => {
							el.style.pointerEvents = 'auto';
							el.disabled = false;
						},
						() => {
							el.style.pointerEvents = 'auto';
							el.disabled = false;
						}
					)
					.catch(() => {
						el.style.pointerEvents = 'auto';
						el.disabled = false;
					});
			});
		}
	});
};

export default Directive;
